/* 控制及读取硬件 */
#ifndef _CONTROLLER_H_
#define _CONTROLLER_H_
#include <Ticker.h>
#include <Arduino.h>
#ifdef ESP32
#define PIN_OPEN 27 //开门引脚D4
#define PIN_CLOSE 14 //关门引脚D5
#define PIN_OPEN_STATUS 32 //检测开门引脚
#define PIN_CLOSE_STATUS 33 //检测关门引脚
#define PIN_MOTOR_STATUS_OPEN 25 //检测电机开门中引脚
#define PIN_MOTOR_STATUS_CLOSE 26  //检测电机关门中引脚
#elif defined(ESP8266)
#define PIN_OPEN 4 //开门引脚D1
#define PIN_CLOSE 5 //关门引脚D2
#define PIN_OPEN_STATUS 12 //检测开门引脚D6
#define PIN_CLOSE_STATUS 13 //检测关门引脚D7
#define PIN_MOTOR_STATUS_OPEN 14 //检测电机开门中引脚D5
#define PIN_MOTOR_STATUS_CLOSE 0  //检测电机关门中引脚D8
#endif

class Controller{
  private:
  Ticker ticker;
  Ticker ticker2;
  String pinStatus;
  
  static void ICACHE_RAM_ATTR openFun();
  static void ICACHE_RAM_ATTR closeFun();
  static void ICACHE_RAM_ATTR motorOpenFun();
  static void ICACHE_RAM_ATTR motorCloseFun();
  static void ICACHE_RAM_ATTR pauseFun();
  public:
  Controller();
    // 定义一个指向回调函数的指针
  static void (*eventCallback)(const String &);  // 回调函数，传递一个参数,在本类中直接调用eventCallback("文本");就会触发setEventCallback中的函数

  void setEventCallback(void (*callback)(const String &));
  void open();//打开车库
  void close();//关闭车库
  String readSwitch();//读取车库门开关状态1.半开中:halfway;2.已打开:opened;3.已关闭:closed;格式{"status":"opened"};
  String readMotor();//读取电动机运行的状态1.停止:stopping;2.打开中:opening;3.关闭中:closing;
 // pinActionFun(const String &pinStatus);//引脚动作自动执行
};
extern Controller controller;

#endif//_CONTROLLER_H_